using UnityEngine;

namespace CinemaDirector
{
	[CutsceneItem("GG-Action", "Rotate")]
	public class RotateAction : CinemaActorAction
	{
		public GGVRotation start;

		public GGVRotation end;

		protected Transform actorTransform;

		public override void Initialize()
		{
			base.Initialize();
			start.Init(base.Cutscene.variables);
			end.Init(base.Cutscene.variables);
		}

		public override void Trigger(GameObject actor)
		{
			if (!(actor == null))
			{
				actorTransform = actor.transform;
				start.value.SetCurrent(actorTransform);
				end.value.SetCurrent(actorTransform);
				SetTime(0f);
			}
		}

		public override void End(GameObject actor)
		{
			if (!(actor == null))
			{
				actorTransform = actor.transform;
				start.value.SetCurrent(actorTransform);
				end.value.SetCurrent(actorTransform);
				SetTime(1f);
			}
		}

		public override void UpdateTime(GameObject Actor, float time, float deltaTime)
		{
			if (!(duration <= 0f) && !(actorTransform == null))
			{
				float time2 = time / duration;
				SetTime(time2);
			}
		}

		private void SetTime(float normTime)
		{
			Vector3 localEuler = start.value.GetLocalEuler(actorTransform);
			Vector3 localEuler2 = end.value.GetLocalEuler(actorTransform);
			actorTransform.rotation = Quaternion.Euler(Vector3Ex.LerpNotClamped(localEuler, localEuler2, normTime));
		}
	}
}
